﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WeiXinPF.Framework.Data.Collections
{
    /// <summary>
    /// 分页DTO集合对象
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public partial class PagingDTO<T> : List<T>, IPagingDTO<T>
    {
        public PagingDTO(IEnumerable<T> items)
        {
            AddRange(items);
        }

        /// <summary>
        /// 当前页
        /// </summary>
        public int PageIndex { get; set; }

        /// <summary>
        /// 每页条数
        /// </summary>
        public int PageSize { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int PageNumber { get; set; }

        /// <summary>
        /// 数据总条数
        /// </summary>
        public int TotalItemCount { get; set; }

        /// <summary>
        /// 数据集合
        /// </summary>
        public List<T> List { get; set; }

        /// <summary>
        /// 
        /// </summary>
        public int TotalPageCount
        {
            get { return (int)Math.Ceiling((double)TotalItemCount / PageSize); }
        }

        /// <summary>
        /// 
        /// </summary>
        public int StartPosition
        {
            get { return (PageNumber - 1) * PageSize + 1; }
        }

        /// <summary>
        /// 
        /// </summary>
        public int EndPosition
        {
            get { return PageNumber * PageSize > TotalItemCount ? TotalItemCount : PageNumber * PageSize; }
        }
    }
}
